package io.renren.modules.app.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.renren.modules.app.entity.ResidentEntity;
import io.renren.modules.app.entity.UserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ResidentDao extends BaseMapper<ResidentEntity> {

    @Select("SELECT * FROM user_resident_personnel WHERE iphone = #{iPhone} AND ID = #{ID}")
    ResidentEntity queryByIphoneAndId(@Param("iphone") String iPhone, @Param("ID") String ID);

    @Update("UPDATE user_resident_personnel SET open_id = #{openId} WHERE iphone = #{iPhone} AND ID = #{ID}")
    void updateOpenIdByIphoneAndId(@Param("openId") String openId, @Param("iphone") String iPhone, @Param("ID") String ID);

    @Select("SELECT * FROM user_resident_personnel WHERE user_id = #{userId}")
    ResidentEntity selectByUserId(@Param("userId") int userId);

    // 更新iphone, CarDealer, sex字段的方法，通过user_id定位
    @Update("UPDATE user_resident_personnel SET iphone = #{iphone}, CarDealer = #{carDealer}, sex = #{sex}, ID = #{ID} WHERE user_id = #{userId}")
    void updateByUserId(@Param("userId") int userId, @Param("iphone") String iphone, @Param("carDealer") String carDealer, @Param("sex") String sex,@Param("ID") String ID);

}

